package web

import (
	"github.com/gin-gonic/gin"
	uuid "github.com/satori/go.uuid"
	"net/http"
	"testPaper/common"
	"testPaper/model"
	"testPaper/response"
)

// 创建标签
func CreatTag(c *gin.Context) {
	DB := common.GetDB()
	name := c.PostForm("name")
	sortId := c.PostForm("sort_id")
	if name == "" {
		response.Reponse(c, http.StatusOK, 422, nil, "标签名不能为空")
		return
	} else if sortId == "" {
		response.Reponse(c, http.StatusOK, 422, nil, "分类id传入不正确")
		return
	}
	tagId := uuid.NewV1().String()

	tag := model.TestPaperTag{
		Name:   name,
		SortId: sortId,
		TagId:  tagId,
	}
	DB.Create(&tag)
	response.Reponse(c, http.StatusOK, 200, nil, "创建成功")
	return
}
